home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 1 / ETO Development Tools 1.iso / Essentials / MacApp Documentation / MacApp AppleLink Messages / MacApp.Tech$ Oct 89 / Z0053-Re WindowMenu-Oct89 < prev    next >
Encoding:
Text File  |  1989-10-12  |  4.9 KB  |  154 lines  |  [TEXT/GEOL]

  1. Item    6759812                         12-Oct-89        03:10
  2.  
  3. From:   AU0008                          Kopfwerk EDV SW Entwicklung
  4.  
  5. To:     MACAPP.TECH$                    MACAPP Tech
  6.  
  7. cc:     D2652                           Strategic Planning Sys, D Bell,PRT
  8.  
  9. Sub:    RE: WindowMenu
  10.  
  11. Don,
  12. here is my receipe for a windows menu. It is a modification of an articel in a
  13. pre-FrameWorks. I use it in my application and it works with 2.0b9. The window
  14. menu is a hierarchical menu.
  15.  
  16. >In the interface part declare following constants:
  17. CONST
  18.    cChooseWind    =   3000;    { command menu number for dis/enabling }
  19.    mWindowsMenu   =   17;      { menuID for hier. windows menu }
  20.  
  21. >Add a new field to your application class and override two methods:
  22.  
  23.    TYourApplication = OBJECT(TApplication)
  24.       fWindowMenuList      : TList;              (* needed for a window menu *)
  25.       PROCEDURE TYourApplication.IApplication;
  26.       PROCEDURE TYourApplication.DoSetUpMenus;   OVERRIDE;
  27.       FUNCTION  TYourApplication.DoMenuCommand (aCmdNumber: CmdNumber):
  28.                                                             TCommand; OVERRIDE;
  29.       (* your fields and methods… *)
  30.    END;
  31.  
  32. >In the TYourApplication.IYourApplication method initialize the list
  33.  
  34.    fWindowMenuList:= NewList;
  35.  
  36. >Implementation of DoSetUpMenus and DoMenuCommand
  37.  
  38. {$S ARes}
  39. PROCEDURE TYourApplication.DoSetUpMenus;   OVERRIDE;
  40. VAR
  41.    theWindowsMenu     : MenuHandle;
  42.    item, j            : INTEGER;
  43.    title              : str255;
  44.  
  45.    PROCEDURE AddToWindowsMenu(aWindow: TWindow);
  46.    BEGIN
  47.       if (aWindow <> gClipWindow) & aWindow.isShown then
  48.                                   { don´t add clipboard and invisible windows }
  49.       BEGIN
  50.          GetWTitle(aWindow.fWmgrWindow, title);
  51.          AppendMenu(theWindowsMenu, title);  { add the title to the real menu }
  52.          fWindowMenuList.InsertLast(aWindow);
  53.                             { add it also to our description of the real word }
  54.          item:= succ(item);
  55.          EnableItem(theWindowsMenu, item);             { enable this new item }
  56.          if aWindow = GetActiveWindow then
  57.                                  { the item of the frontwindow will be marked }
  58.             SetItemMark(theWindowsMenu, item, chr(diamondMark));
  59.       END;
  60.    END;
  61.  
  62. BEGIN
  63.    INHERITED DoSetUpMenus;
  64.  
  65.    (* enable your favorite items here *)
  66.  
  67.    theWindowsMenu:= GetMHandle(mWindowsMenu);
  68.    for j:= 1 to CountMItems(theWindowsMenu) do         { remove all old items }
  69.       DelMenuItem(theWindowsMenu, 1);
  70.    fWindowMenuList.DeleteAll;                  { remove also our descriptions }
  71.                                                { of the real menu world       }
  72.  
  73.    item:= 0;                 { initialize the counter of items we will append }
  74.    ForAllWindowsDo(AddToWindowsMenu);   { append all windowtitles to the menu }
  75.    Enable(cChooseWind, item > 0);
  76.                               { enable the menu in case of submenuitems exist }
  77. END;
  78.  
  79.  
  80. {$S ASelCommand}
  81. FUNCTION TYourApplication.DoMenuCommand (aCmdNumber: CmdNumber):
  82.                                                             TCommand; OVERRIDE;
  83. VAR
  84.    menu, menuItem, i   : INTEGER;
  85.    newFrontWindow      : TWindow;
  86.    theWindowsMenu      : MenuHandle;
  87.    aLong               : LongInt;
  88.  
  89. BEGIN
  90.    DoMenuCommand:= gNoChanges;
  91.    CASE aCmdNumber OF
  92.       (* here are your special command numbers *)
  93.       (* e.g.: cHelp:   BEGIN ……   *)
  94.  
  95.       OTHERWISE
  96.                BEGIN
  97.                   if aCmdNumber < 0 then
  98.                                       { dynamic command numbers are negative! }
  99.                   BEGIN
  100.                      CmdToMenuItem(aCmdNumber, menu, menuItem);
  101.                      if menu = mWindowsMenu then      { user chooses a window }
  102.                      BEGIN
  103.                         newFrontWindow:= TWindow(fWindowMenuList.At(menuItem));
  104.                         if newFrontWindow <> GetActiveWindow then
  105.                                                          { situation changed? }
  106.                            SelectWindow(newFrontWindow.fWmgrWindow);
  107.                         DoMenuCommand:= gNoChanges;
  108.                      END ELSE
  109.                         DoMenuCommand := INHERITED DoMenuCommand(aCmdNumber);
  110.                   END ELSE
  111.                      DoMenuCommand:= INHERITED DoMenuCommand (aCmdNumber);
  112.                END;
  113.    END;
  114. END;
  115.  
  116. >In your resource description file create a hierarchical window menu without
  117. >items in it.
  118.  
  119. #define   cChooseWind 3000
  120.  
  121. resource 'cmnu' (2) {
  122.    2,
  123.    textMenuProc,
  124.    0x7FFFFBAF,
  125.    enabled,
  126.    "File",
  127.     {
  128. //      place you favorite items here
  129.  
  130. //   add a hierarchical window menu
  131.       "Choose Window", noIcon, "\0x1B", "\0x11", plain, cChooseWind;
  132.  
  133.       "-", noIcon, noKey, noMark, plain, nocommand;
  134.       "Quit", noIcon, "Q", noMark, plain, cQuit
  135.    }
  136. };
  137.  
  138.  
  139. resource 'cmnu' (17) {
  140.    17,
  141.    textMenuProc,
  142.    0x7FFFFFF7,
  143.    enabled,
  144.    "Choose Window",
  145.    {   }
  146. };
  147.  
  148. Hope this helps,
  149. kind regards,
  150.  
  151. Tommi GESSL,
  152. KOPFWERK SW. Dev.
  153.  
  154.